<?php
try{
	include '../ini.php';
    include '../classes/xl_brand_product.php';
    $dt_xl_brand_product=new xl_brand_product;
   
    if(empty($_GET['id'])){
        throw new Exception('Không tồn tại mã này');
    }
    $read_brand=$dt_xl_brand_product->read($_GET['id']);
    if($read_brand === false){
        throw new Exception('Không tồn tại mã này');
    }
    if($_GET['id'] != $read_brand['id']){
        $_GET['id']=$dt_xl_admin->removeSQLI($_GET['id']);
        header("Location: brand_products_update.php?id=".$_GET['id']);
    }
    $read_list=$dt_xl_brand_product->read_list();
    $dt_smarty->assign('location',count($read_list));
    $dt_smarty->assign('read_brand',$read_brand);
    $dt_smarty->assign('read_list',$read_list);
	$contenForLayout=$dt_smarty->fetch('product/brand_products_update.tpl');
	$dt_smarty->assign('contenForLayout',$contenForLayout);
	$dt_smarty->assign('titleForLayout','Chỉnh sữa thương hiệu sản phẩm');
	$dt_smarty->display('layout/defaults.tpl');
    $dbh=NULL;
	
} catch(Exception $e){
    $dbh=NULL;
	$_SESSION['msg']=$e->getMessage();
    $_SESSION['type_msg']='error';
    if(empty($_SERVER['HTTP_REFERER'])){
        header('Location: brand_products_list.php');
    }else{
        header('Location:'.$_SERVER['HTTP_REFERER']);
    }
	
}